
var type = GetQueryString("type");
var date = getDay(0);
	
$(document).ready(function(){
	onload(); 
});

function onload(){
	if( type=='week' ){
		$('#html_name').html( '本周' );
		week();
	}else if( type=='month' ){
		$('#html_name').html( '本月' );
		month();
	}else if( type=='year' ){
		$('#html_name').html( '本年' );
		year();
	}
	
}


/**
 * 本周
 * @returns
 */
function week() {
	$.ajax({
		type : "post",
		url : "../jhcvs_goods/oneweek.do",
		data:{"date":date},
		dataType : "json",
		success : function(suc) {
			console.log(suc);
			var time = suc.data.time.substring(0,10);
			$('#now').html(time );
			$('#time').html('数据更新时间：'+(suc.data.time) );
			
			$('#sum').html( formatCurrency(suc.data.sum) );
			$('#yingwancheng').html( formatCurrency(suc.data.yingwancheng) );
			var jindu = parseFloat(suc.data.sum/suc.data.yingwancheng*100).toFixed(2);
			$('#jindu').attr("style","width:"+jindu+"%").parent().attr("data-percent",jindu+"%");
			var mubiaowcl = parseFloat(suc.data.sum/suc.data.mubiao*100).toFixed(2);
			$('#mubiao').html( "￥"+formatCurrency(suc.data.mubiao) );
			$('#mubiaowcl').html( mubiaowcl+"%" );
			
			var sdata=[];
			var paixu=[];
			var list=suc.tubiao;
			for(var i=0;i<list.length;i++){
				sdata.push(list[i].money);
				paixu.push(list[i].money);
			};
			paixu.sort(function(a,b){return b - a;});
			$('#tu').css('height','800px');
			var zhuzhuang = echarts.init(document.getElementById('tu'));
			var option = {
					   
					    tooltip: {
					        trigger: 'axis',
					        axisPointer: {
					            type: 'shadow'
					        },
					        show:false
					    },
					    
					    grid: {
					        left: '3%',
					        right: '4%',
					        bottom: '3%',
					        containLabel: true
					    },
					    xAxis: {
					        type: 'value',
					        boundaryGap: [0, 0.02],
					        axisTick: {
				                alignWithLabel: true
				            },						    
				             axisLabel: {  
						    	   interval:0,  
						    	   rotate:15  
						    	}
					    },
					    yAxis: {
					        type: 'category',
					        data: ['周一','周二','周三','周四','周五','周六','周日'],
					        inverse:'true'
					    },
					    series: [
					        
					        {
					           
					            type: 'bar',
					            data: sdata,
					            itemStyle: {  
					                        normal: {  
					                            label: {  
					                                show: true,//是否展示
					                                position:'inside',
					                               // distance:150,
					                                textStyle: {  
					                                    fontWeight:'bolder',  
					                                    fontSize : '12',  
					                                    fontFamily : '微软雅黑', 
					                                    
					                                }
					                            },
					                            color: function (params){
					                            	var colorList = ['rgb(72,176,225)','rgb(235,97,0)','rgb(243,152,0)','rgb(0,158,150)','rgb(47,69,84)','rgb(11,196,93)'];
							                        if(parseFloat(params.data)>parseFloat(paixu[1])){
							                        	return colorList[1];
							                        }else if((parseFloat(params.data)<=parseFloat(paixu[1]))&(parseFloat(params.data)>parseFloat(paixu[3]))){
							                        	return colorList[2];
							                        }else{
							                        	return colorList[3];
							                        }
							                    }
					                        }  
					                    }
					        },
					        {
					            
					            type:'line',
					            data:sdata,
					          
					        }
					    ]
					};
			 zhuzhuang.setOption(option);
			 hideloading();
			
		}
	});

}
/**
 * 本月
 * @returns
 */
function month(){

	$.ajax({
		type : "post",
		url : "../jhcvs_goods/onemonth.do",
		data:{"date":date},
		dataType : "json",
		success : function(suc) {
			console.log(suc);
			var time = suc.data.time.substring(0,10);
			$('#now').html(time );
			$('#time').html('数据更新时间：'+(suc.data.time) );
			
			$('#sum').html( formatCurrency(suc.data.sum) );
			$('#yingwancheng').html( formatCurrency(suc.data.yingwancheng) );
			var jindu = parseFloat(suc.data.sum/suc.data.yingwancheng*100).toFixed(2);
			$('#jindu').attr("style","width:"+jindu+"%").parent().attr("data-percent",jindu+"%");
			var mubiaowcl = parseFloat(suc.data.sum/suc.data.mubiao*100).toFixed(2);
			$('#mubiao').html( "￥"+formatCurrency(suc.data.mubiao) );
			$('#mubiaowcl').html( mubiaowcl+"%" );
			
			var sdata = [];
			var paixu = [];
			var ydata = [];
			var list=suc.tubiao;
			for(var i=0;i<list.length;i++){
				sdata.push(list[i].money);
				paixu.push(list[i].money);
				ydata.push(list[i].inDate);
				
			};
			console.log(ydata);
			console.log(sdata);
			paixu.sort(function(a,b){return b - a;});
			$('#tu').css('height','800px');
			var zhuzhuang = echarts.init(document.getElementById('tu'));
			var option = {
					   
					    tooltip: {
					        trigger: 'axis',
					        axisPointer: {
					            type: 'shadow'
					        },
					        show:false
					    },
					    
					    grid: {
					        left: '3%',
					        right: '4%',
					        bottom: '4%',
					        containLabel: true
					    },
					    xAxis: {
					        type: 'value',
					        boundaryGap: [0, 0.02],
					        axisTick: {
				                alignWithLabel: true
				            },						    
				             axisLabel: {  
						    	   interval:0,  
						    	   rotate:15  
						    	}
					    },
					    yAxis: {
					        type: 'category',
					        data: ydata,
					        inverse:'true'
					    },
					    series: [
					        
					        {
					           
					            type: 'bar',
					            data: sdata,
					            itemStyle: {  
					                        normal: {  
					                            label: {  
					                                show: true,//是否展示
					                                position:'inside',
					                               // distance:150,
					                                textStyle: {  
					                                    fontWeight:'bolder',  
					                                    fontSize : '12',  
					                                    fontFamily : '微软雅黑', 
					                                    
					                                }
					                            },
					                            color: function (params){
					                            	var colorList = ['rgb(72,176,225)','rgb(235,97,0)','rgb(243,152,0)','rgb(0,158,150)','rgb(47,69,84)','rgb(11,196,93)'];
							                        if(parseFloat(params.data)>parseFloat(paixu[1])){
							                        	return colorList[1];
							                        }else if((parseFloat(params.data)<=parseFloat(paixu[1]))&(parseFloat(params.data)>parseFloat(paixu[3]))){
							                        	return colorList[2];
							                        }else{
							                        	return colorList[3];
							                        }
							                    }
					                        }  
					                    }
					        },
					        {
					            
					            type:'line',
					            data:sdata,
					          
					        }
					    ]
					};
			 zhuzhuang.setOption(option);
			 hideloading();
			
		}
	});

}

/**
 * 本年
 * @returns
 */
function year(){

	$.ajax({
		type : "post",
		url : "../jhcvs_goods/oneyear.do",
		data:{"date":date},
		dataType : "json",
		success : function(suc) {
			console.log(suc);
			var time = suc.data.time.substring(0,10);
			$('#now').html(time );
			$('#time').html('数据更新时间：'+(suc.data.time) );
			
			$('#sum').html( formatCurrency(suc.data.sum) );
			$('#yingwancheng').html( formatCurrency(suc.data.yingwancheng) );
			var jindu = parseFloat(suc.data.sum/suc.data.yingwancheng*100).toFixed(2);
			$('#jindu').attr("style","width:"+jindu+"%").parent().attr("data-percent",jindu+"%");
			var mubiaowcl = parseFloat(suc.data.sum/suc.data.mubiao*100).toFixed(2);
			$('#mubiao').html( "￥"+formatCurrency(suc.data.mubiao) );
			$('#mubiaowcl').html( mubiaowcl+"%" );
			
			var sdata=[];
			var paixu=[];
			var ydata=[];
			var list=suc.tubiao;
			for(var i=0;i<list.length;i++){
				sdata.push(list[i].money);
				paixu.push(list[i].money);
				ydata.push(list[i].inDate);
			};
			paixu.sort(function(a,b){return b - a;});
			$('#tu').css('height','800px');
			var zhuzhuang = echarts.init(document.getElementById('tu'));
			var option = {
					   
					    tooltip: {
					        trigger: 'axis',
					        axisPointer: {
					            type: 'shadow'
					        },
					        show:false
					    },
					    
					    grid: {
					        left: '3%',
					        right: '4%',
					        bottom: '3%',
					        containLabel: true
					    },
					    xAxis: {
					        type: 'value',
					        boundaryGap: [0, 0.02],
					        axisTick: {
				                alignWithLabel: true
				            },						    
				             axisLabel: {  
						    	   interval:0,  
						    	   rotate:15  
						    	}
					    },
					    yAxis: {
					        type: 'category',
					        data: ydata,
					        inverse:'true'
					    },
					    series: [
					        
					        {
					           
					            type: 'bar',
					            data: sdata,
					            itemStyle: {  
					                        normal: {  
					                            label: {  
					                                show: true,//是否展示
					                                position:'inside',
					                               // distance:150,
					                                textStyle: {  
					                                    fontWeight:'bolder',  
					                                    fontSize : '12',  
					                                    fontFamily : '微软雅黑', 
					                                    
					                                }
					                            },
					                            color: function (params){
					                            	var colorList = ['rgb(72,176,225)','rgb(235,97,0)','rgb(243,152,0)','rgb(0,158,150)','rgb(47,69,84)','rgb(11,196,93)'];
							                        if(parseFloat(params.data)>parseFloat(paixu[1])){
							                        	return colorList[1];
							                        }else if((parseFloat(params.data)<=parseFloat(paixu[1]))&(parseFloat(params.data)>parseFloat(paixu[3]))){
							                        	return colorList[2];
							                        }else{
							                        	return colorList[3];
							                        }
							                    }
					                        }  
					                    }
					        },
					        {
					            
					            type:'line',
					            data:sdata,
					          
					        }
					    ]
					};
			 zhuzhuang.setOption(option);
			 hideloading();
			
		}
	});

}



